<template>
    <slot :controller="controller" :store="store" :model="model" :actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }">
        <AppWizardPanel
            v-bind="$attrs"
            :class="classNames"
            :id="controlID"
            :showStepBar="model.showStepBar"
            :buttonCaption="model.buttonCaption"
            :wizardForms="model.wizardForms"
            :wizardSteps="model.wizardSteps"
            :activeEditForm="store.activeEditForm"
            :stepTags="store.stepTags"
            @prev="()=>controller.clickPrev()"
            @next="()=>controller.clickNext()"
            @finish="()=>controller.clickFinish()">
            <template #form>
                <component
                    v-if="store.activeEditForm.codeName"
                    :name="store.activeEditForm.name"
                    :is="componentList[store.activeEditForm.name]"
                    :actions="store.activeEditForm.actions"
                    :context="store.context"
                    :viewParams="store.viewParams"
                    :pLoadingHelper="store.loadingHelper"
                    :pViewCtx="store.viewCtx"
                    :closeView="closeView"
                    :openView="openView"
                    :newView="newView"
                    @ctrl-init="(name: string, ability: ICtrlAbility) => { handleCtrlInit(controller, name, ability) }"
                    @ctrl-action="(name: string , action:any , data: IParam[]) => { handleCtrlAction(controller, name, action, data) }"
                    @ctrl-destroy="(name: string , data: IParam) => { handleCtrlDestroy(controller, name, data) }" />
            </template>
        </AppWizardPanel>
    </slot>
</template>
<script setup lang="ts">
// 基于template/src/widgets/{{appEntities}}/{{ctrls@WIZARDPANEL}}-wizard-panel/{{spinalCase ctrl.codeName}}-wizard-panel-base.vue.hbs生成
import { AppWizardPanel } from '@components/widgets/wizard-panel';
import wizardpanel_form_firstform from '@widgets/ibizbook/guide-view-form-form/guide-view-form-form.vue';
import wizardpanel_form_secondform from '@widgets/ibizbook/guide-borrow-form-form/guide-borrow-form-form.vue';
import wizardpanel_form_thirdform from '@widgets/ibizbook/guide-return-form-form/guide-return-form-form.vue';
import { useProps, useBasic, useAction, useController } from './state-field-guide-wizard-panel-hook';
import { ICtrlAbility, WizardPanelActionType, IWizardPanelAbility, IWizardPanelStore, IParam, IViewLogicInput } from "@/core/interface";

// 组件注册
const componentList:any = {
    wizardpanel_form_firstform,
    wizardpanel_form_secondform,
    wizardpanel_form_thirdform,
}

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { 
    model,
    controlID, 
    getClassNames, 
    useNavParamsBind, 
    useEventBind,
    handleCtrlInit, 
    handleCtrlAction, 
    handleCtrlDestroy
} = useBasic(props);

const emit = defineEmits<{
    (event: 'ctrl-action', name: string, action: WizardPanelActionType, data: IParam[]): void;
    (event: 'ctrl-init', name: string, data: IWizardPanelAbility): void;
    (event: 'ctrl-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  return getClassNames(props);
});

const controller = useController(props, evt, { controlID });

useNavParamsBind(controller, props);

const store: IWizardPanelStore = controller.getStore();

onMounted(() => {
    controller.ctrlMounted();
});
onUnmounted(() => {
    controller.ctrlDestroy();
})
</script>